<?php
namespace app\model\crm;

use think\Model;

class Payment extends Model
{
    // 设置表名
    protected $name = 'crm_payment';
    
    // 自动写入时间戳
    protected $autoWriteTimestamp = true;
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    
    // 定义字段类型
    protected $type = [
        'amount' => 'float',
        'payment_type' => 'integer',
        'status' => 'integer'
    ];
    
    // 关联订单
    public function order()
    {
        return $this->belongsTo(Order::class, 'order_id');
    }
    
    // 获取付款方式标签
    public function getPaymentTypeTextAttr($value, $data)
    {
        $types = [
            1 => '银行转账',
            2 => '现金支付',
            3 => '微信支付',
            4 => '支付宝',
            5 => '其他'
        ];
        return $types[$data['payment_type']] ?? '未知';
    }
    
    // 获取付款状态标签
    public function getStatusTextAttr($value, $data)
    {
        $status = [
            1 => '待确认',
            2 => '已确认',
            3 => '已驳回'
        ];
        return $status[$data['status']] ?? '未知';
    }
}